//获取应用实例
const app = getApp()
const TAG = "createroom.js";
const requestCreateRoom = "";
Page({
  data: {
    roomName: " ",
    showToChatDialog: false,
    titleMsg: "申请会话",
    titleText: "提示",
    determineBtnText: "好的",
    cancleBtnText: "不好",
    cancleBtnHidden: true,
    toChatDialogHidden: true,
  },

  onLoad: function () {
    console.log('>>>[' + TAG + '页面周期信息：] onLoad');
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log('>>>[' + TAG + '页面周期信息：] onShow');
  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    console.log('>>>[' + TAG + '页面周期信息：] onHide');
  },

  onReady: function () {
    console.log('>>>[' + TAG + '页面周期信息：] onReady');

  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    console.log('>>>[' + TAG + '页面周期信息：] onUnload');

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log('>>>[' + TAG + '页面周期信息：] onPullDownRefresh');

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('>>>[' + TAG + '页面周期信息：] onReachBottom');
  },

  bindKeyInput: function (e) {
    this.setData({
      roomName: e.detail.value
    })
  },

  onDetermineEvent: function (e) {
    console.log("onDetermineEvent=" + e.detail.determine);
  },

  creatRoom: function () {
    var context = this;
    wx.request({
      url: requestCreateRoom,
      method: "post",
      data: {
        roomName: context.roomName,
      },
      success: function (res) {
        console.log("creatRoom, result is: " + res);
        if (res.statusCode === 200) {
          console.log(res.data);

        } else {
          wx.showToast({
            title: '创建房间失败',
            icon: 'none',
            duration: 2000
          })
        }
      },
      fail: function () {
        wx.showToast({
          title: '创建房间失败',
          icon: 'none',
          duration: 2000
        })
      },
    });
    var url = '../room/room';
    wx.navigateTo({
      url: url,
    });
  }
})
